package top.kaoshanji.p1ch01d;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * 代码清单 p1ch01d-02：自定义资源使用AutoCloseable接口的示例(1.5节)
 * author kaoshanji
 * ^_^
 * create time 2024/12/22 20:18
 */
public class CustomResource implements AutoCloseable {

    private static final Logger logger = LogManager.getLogger(CustomResource.class);

    public static void main(String[] args) {
        logger.info("...代码清单 p1ch01d-02：自定义资源使用AutoCloseable接口的示例(1.5节)...");

        try {
            new CustomResource().useCustomResource();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    @Override
    public void close() throws Exception {
        System.out.println("进行资源释放.");
    }

    public void useCustomResource() throws Exception {
        try (CustomResource resource = new CustomResource()) {
            System.out.println("使用资源.");
        }
    }



}
